package com.imc.domain;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.Table;
import javax.persistence.FetchType;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import org.apache.commons.lang.Validate;

/**
 * Defines the staff entity.
 */

@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorValue("staff")
@Table(name = "person")
public class Staff extends Person implements java.io.Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	// private InputStream cv;

	/**
	 * The roles of the staff.
	 */
	@ManyToMany(fetch = FetchType.EAGER)
	@JoinTable(name = "staff_roles")
	private Set<Role> roles = new HashSet<Role>();

	/**
	 * Adds the specified role. Ignores duplicates.
	 * 
	 * @param theRole
	 *            The role to add. It cannot be null.
	 * @return true if the role was added
	 */
	public boolean addRole(final Role role) {
		Validate.notNull(role, "The role cannot be null");
		return roles.add(role);
	}

	/**
	 * Removes the specified role.
	 * 
	 * @param theRole
	 *            The role to be deleted.
	 * @return true if the list contained the specified role
	 */
	public boolean removeRole(final Role role) {
		return roles.remove(role);
	}

	/**
	 * Returns the roles of the staff.
	 * 
	 * @return the roles
	 */
	public Set<Role> getRoles() {
		return roles;
	}

}
